package demo5;

import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 */
public class Dog extends Animal {
    public Dog(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(this.name+"正在吃狗粮");
    }
    public void bark(){
        System.out.println(this.name+"正在汪汪叫");
    }

   /* @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }*/
   @Override
   public String toString() {
       return "Dog{姓名：'" + name + "', 年龄：" + age + "}";
   }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    public boolean equals(Object object){
        if(this == null){
            return false;
        }
        if (this == object){
            return true;
        }
        //object不是Dog类的对象
        if (!(object instanceof Dog)){
            return false;
        }
        Dog dog = (Dog) object;
        return this.name.equals(dog.name) && this.age == dog.age;
    }

}
